
function previ(fang) {
    if (fang < 10){
        bdhtml=window.document.body.innerHTML;//获取当前页的html代码
        sprnstr="<!--startprint"+fang+"-->";//设置打印开始区域
        eprnstr="<!--endprint"+fang+"-->";//设置打印结束区域
        prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
        window.document.body.innerHTML=prnhtml;
        window.print();
        window.document.body.innerHTML=bdhtml;
    } else {
        window.print();
    }
}




//设置cookie
var setCookie = function (name, value, day) {
    //当设置的时间等于0时，不设置expires属性，cookie在浏览器关闭后删除
    var expires = day * 24 * 60 * 60 * 1000;
    var exp = new Date();
    exp.setTime(exp.getTime() + expires);
    document.cookie = name + "=" + value + ";expires=" + exp.toUTCString();
};
//删除cookie
var delCookie = function (name) {
    setCookie(name, ' ', -1);
};

//获取产品详细信息
function userPasswordReset(obj) {
    // alert("修改产品的id："+obj);
    //传递cookie
    setCookie('id', obj, 7);
    loadPage("person/mapengxin/Customer.html");
    // delCookie('id',' ',-1)
}

//查询银行
$(function () {
    var str = "";
    $.ajax({
        url: "getBank",
        type: "POST",
        dataType: 'json',
        success: function (data) {
            // console.log(data.Bank.length);
            str = "<option></option>";
            for (var i = 0; i < data.Bank.length; i++) {
                str += "<option value='" + data.Bank[i].BANKNAME + "'>" + data.Bank[i].BANKNAME + "</option>";
            }
            $("#userState").html(str);
        }
    })
});
//查询产品名称
$(function () {
    var str = "";
    $.ajax({
        url: "getProduct",
        type: "POST",
        dataType: 'json',
        success: function (data) {
            // console.log(data);
            str = "<option></option>";
            for (var i = 0; i < data.PHY.length; i++) {
                str += "<option value='" + data.PHY[i].LOANNAME + "'>" + data.PHY[i].LOANNAME + "</option>";
            }
            $("#sUserBank").html(str);
        }
    })
});
//查询状态
$(function () {
    var str = "";
    $.ajax({
        url: "getStat",
        type: "POST",
        dataType: 'json',
        success: function (data) {
            // console.log(data);
            str = "<option></option>";
            for (var i = 0; i < data.Stat.length; i++) {
                str += "<option value='" + data.Stat[i].StatusName + "'>" + data.Stat[i].StatusName + "</option>";
            }
            $("#sUserOrg").html(str);
        }
    })
});

//清空实现
function resetQuery() {

    $("#userAccount").val(""),
        $("#userName").val(""),
        $("#sUserRole").val(""),
        $("#sUserBank").val(""),
        $("#sUserOrg").val(""),
        $("#userState").val("")
}

//查询
$("#queryBtn").click(function () {
    var filters = {
        'numbering': $("#userAccount").val(),
        'numbered': $("#userName").val(),
        'customerName': $("#sUserRole").val(),
        'product': $("#sUserBank").val(),
        'state': $("#sUserOrg").val(),
        'Rabobank': $("#userState").val()
    };
    grid.jqGrid("setGridParam", {postData: filters, page: 1});
    grid.trigger('reloadGrid');
});

//根据条件查询
$(function () {

    //加载该页面前，先判断该模块的权限
    //获取当前登录的用户的权限
    var permission = document.cookie.split(";")[1].split("=")[1];
    var b = String(permission).split('');
    for (var i = 0; i < b.length; i++) {
        console.log(b[i]);
    }
    var moudle42 = b[13];
    //如果模块权限为1，即只能查询此模块下的数据，不能进行修改（禁用和重置密码不能使用）
    //系统管理
    flag = true;
    if (moudle42 == 1) {
        $("#dayin").css('display', 'none');
        flag = false;
    }

    var pageNo = 1;
    var pageSize = 5;
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";
    //初始化数据表格
    grid = $(grid_selector).jqGrid({
        datatype: "json",
        url: 'getInformation',
        mtype: 'POST',
        page: pageNo,
        postData: {
            'numbering': $("#userAccount").val(),
            'numbered': $("#userName").val(),
            'customerName': $("#sUserRole").val(),
            'product': $("#sUserBank").val(),
            'state': $("#sUserOrg").val(),
            'Rabobank': $("#userState").val(),
        },
        height: 380,
        width: 300,
        colNames: ['贷款编号', '客户编号', '客户名称', '产品名称', "审批状态", "所属银行", "初审得分", "授信额度（元）", '授信期限（月）',
            "信用评级", "还款方式", "问卷信息", "借款合同"],
        colModel: [

            {name: 'LoanNumber', index: 'LoanNumber', align: 'center', sortable: false},
            {name: 'ID', index: 'ID', align: 'center', sortable: false},
            {
                name: 'CUSTOMERNAME',
                index: 'CUSTOMERNAME',
                align: 'center',
                sortable: false,
                formatter: function (cellvalue, options, list) {
                    return "<a class='btn btn-group btn-xs' onclick='userPasswordReset(\"" + list.LoanNumber + "\")'><i class='fa fa-edit button-in-i'>" + list.CUSTOMERNAME + "</i></a>";
                }
            },
            {name: 'LOANNAME', index: 'LOANNAME', align: 'center', sortable: false},
            {name: 'StatusName', index: 'StatusName', align: 'center', sortable: false},
            {name: 'Bankname', index: 'Bankname', align: 'center', sortable: false},
            {name: 'Fen', index: 'Fen', align: 'center', sortable: false},
            {name: 'CREDITBERIOD', index: 'CREDITBERIOD', align: 'center', sortable: false},
            {name: 'CREDITLIMIT', index: 'CREDITLIMIT', align: 'center', sortable: false},
            {name: 'CREDITGRADE', index: 'CREDITGRADE', align: 'center', sortable: false},
            {name: 'Repayment', index: 'Repayment', align: 'center', sortable: false},
            {
                name: '',
                index: '',
                align: 'center',
                sortable: false,
                formatter: function (cellvalue, options, list) {
                    if (flag == false) {
                        return "<button disabled class='btn btn-group btn-xs' ><i class='fa fa-edit button-in-i'></i>打印</button>";
                    } else {
                        return "<button class='btn btn-group btn-xs'><i class='fa fa-edit button-in-i'></i>打印</button>";
                    }
                }
            },
            {
                name: '',
                index: '',
                align: 'center',
                sortable: false,
                formatter: function (cellvalue, options, list) {
                    if (flag == false){
                        return "<button disabled class='btn btn-group btn-xs' href='action.action'><i class='fa fa-edit button-in-i'></i>下载</button>";
                    }else {
                        return "<button class='btn btn-group btn-xs' href='action.action'><i class='fa fa-edit button-in-i'></i>下载</button>";
                    }
                }
            }
        ],
        viewrecords: true,
        rowNum: pageSize,
        rownumbers: false,//添加左侧行号
        rowList: [5, 10, 15],
        pager: pager_selector,
        altRows: true,
        multiselect: false,
        loadComplete: function (data) {
            var table = this;
            setTimeout(function () {
                updatePagerIcons(table);
            }, 0);
            var h = $(window).height() - ($('#grid-pager')[0].offsetHeight + 15) - ($('.result-table .box')[0].offsetTop + $('.ui-jqgrid-bdiv')[0].offsetTop + 3);
            $('.ui-jqgrid-bdiv').height(h);
        },
        autowidth: true,
        jsonReader: jsonReader,   // json中代表实际模型数据的入口
        rownumWidth: 55,
        prmNames: prmNames,
        recordtext: "显示 {0} - {1} 条 , 共 {20} 条",
        emptyrecords: "没有记录",
        /*loadtext: "正在加载...",*/
        pgtext: "第 {0} 页  ,共 {1} 页"
    });
    //初始化分页条
    showNavGrid(grid_selector, pager_selector);
});